1 /*
2 * Angkor Web Framework
3 *
4 * Distributable under LGPL license.
5 * See terms of license at gnu.org.
6 */
7 package com.tirsen.angkor.widget;
8
9 import com.tirsen.angkor.RenderContext;
10 import com.tirsen.angkor.View;
11
12 import java.io.IOException;
13
14 /***
15 *
16 *
17 * <!-- $Id: Section.java,v 1.5 2002/10/09 21:37:37 tirsen Exp $ -->
18 * <!-- $Author: tirsen $ -->
19 *
20 * @author Jon Tirsén (tirsen@users.sourceforge.net)
21 * @version $Revision: 1.5 $
22 */
23 public class Section extends Container
24 {
25 private String headerLabel;
26 private String background = null;
27 //private String width;
28 //private String height;
29
30 public Section()
31 {
32 }
33
34 public Section(String headerLabel)
35 {
36 setHeaderLabel(headerLabel);
37 }
38
39 public Section(SectionLine line)
40 {
41 add(line);
42 }
43
44 public String getHeaderLabel()
45 {
46 return headerLabel;
47 }
48
49 public void setHeaderLabel(String headerLabel)
50 {
51 this.headerLabel = headerLabel;
52 }
53
54 /***
55 * Can only add Sections or SectionLines to a Section, if you try to add anything else
56 * it a SectionLine will be instantiated for it.
57 */
58 public void add(int index, View element)
59 {
60 if (element instanceof Section || element instanceof SectionLine)
61 {
62 super.add(index, element);
63 }
64 else
65 {
66 super.add(index, new SectionLine(element));
67 }
68 }
69
70 /***
71 * Adds a TextLabel as a string to this section on its own line.
72 */
73 public void add(String text)
74 {
75 add(new TextLabel(text));
76 }
77
78 public int getSectionDepth()
79 {
80 int depth = 0;
81 for (View container = this; container instanceof Section; depth++)
82 {
83 container = container.getContainer();
84 }
85 return depth;
86 }
87
88 public void render(RenderContext context) throws IOException
89 {
90 if (isVisible())
91 {
92 if (getContainer() instanceof Section)
93 {
94 context.startTag("TR");
95 context.startTag("TD");
96 }
97
98 if (getHeaderLabel() != null)
99 {
100 context.startTag("H" + getSectionDepth());
101 context.println(getHeaderLabel());
102 context.endTag("H" + getSectionDepth());
103 }
104
105 String idAttr = " id=\"" + uniqueId(context) + "\"";
106 context.startTag("TABLE width=\"100%\"" + background + idAttr);
107 renderChildren(context);
108
109 context.endTag("TABLE");
110 if (getContainer() instanceof Section)
111 {
112 context.endTag("TD");
113 context.endTag("TR");
114 }
115 }
116 }
117 }
This page was automatically generated by Maven